package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    private OrderService ordersService;
    //提交订单
    @PostMapping("/order/submit")
    public ResultInfo submit(@RequestBody Order order){
        ordersService.submit(order);
        return ResultInfo.success(null);
    }
    //查看订单
    @GetMapping("/order/userPage")
    public ResultInfo findByPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                 @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize){
        Page<Order> page = ordersService.findOrderByPage(pageNum, pageSize);
        return ResultInfo.success(page);
    }
    //查看所有订单
    @GetMapping("/order/list")
    public ResultInfo findList(){
        List<Order> ordersList = ordersService.findList();
        return ResultInfo.success(ordersList);
    }

    // 再来一单
    @PostMapping("/order/again")
    public ResultInfo again(@RequestBody Map<String,Long> param){
        Long id = param.get("id");
        ordersService.againAdd(id);
        return ResultInfo.success(null);
    }


}
